package ui.popups
{
	import base.PopupBase;
	
	import com.demonsters.debugger.MonsterDebugger;
	
	import feathers.controls.Button;
	import feathers.controls.ScrollContainer;
	import feathers.core.FeathersControl;
	import feathers.core.PopUpManager;
	import feathers.layout.HorizontalLayout;
	import feathers.layout.VerticalLayout;
	
	import managers.Config;
	import managers.SoundManager;
	
	import starling.display.Quad;
	import starling.display.Sprite;
	import starling.events.Event;

	public class SettingsPopup extends PopupBase
	{
		private var bg:Quad;
		private var btnClose:Button;
		private var container:ScrollContainer;
		
		public function SettingsPopup()
		{
			
		}
		
		private function onClose(e:Event):void{
			SoundManager.getInstance().playSound(SoundManager.BUTTON_CLICK);
			PopUpManager.removePopUp(this,true);
		}
		
		override protected function draw():void
		{
			// TODO Auto Generated method stub
			super.draw();
			btnClose.validate();
			container.validate();
			setSizeInternal(bg.width,bg.height,true);
			btnClose.x = bg.width - btnClose.width/2;
			btnClose.y = - btnClose.height/2;
			container.x = (bg.width-container.width)/2>>1;
			container.y = (bg.height-container.height)/2>>1;
		}
		
		override protected function initialize():void
		{
			// TODO Auto Generated method stub
			super.initialize();
			bg = new Quad(250,250,0xF1AA00);
			addChild(bg);
			btnClose = new Button();
			btnClose.nameList.add("circleButton");
			btnClose.label ="X";
			btnClose.addEventListener(Event.TRIGGERED,onClose);
			
			addChild(btnClose);
			
			var btnSound:Button = new Button();
			btnSound.nameList.add("test");
			btnSound.label = "Sound";
			btnSound.addEventListener(Event.TRIGGERED, onBtnSound);
			
			var vLayer:VerticalLayout = new VerticalLayout();
			vLayer.paddingTop = 0;
			vLayer.paddingBottom = 20;
			vLayer.paddingRight = 20;
			vLayer.paddingLeft = 40;
			vLayer.gap = 2;
			vLayer.horizontalAlign = HorizontalLayout.HORIZONTAL_ALIGN_CENTER;
			vLayer.verticalAlign = VerticalLayout.HORIZONTAL_ALIGN_CENTER;
			
			container = new ScrollContainer();
			container.layout = vLayer;
			container.addChild(btnSound);
			addChild(container);
		}
		
		private function onBtnSound(e:Event):void{
			SoundManager.getInstance().playSound(SoundManager.BUTTON_CLICK);
			MonsterDebugger.trace("Config.getInsance().isPlayMusic",Config.getInsance().isPlayMusic);
			Config.getInsance().isPlayMusic = !Config.getInsance().isPlayMusic;
			if(Config.getInsance().isPlayMusic){
				SoundManager.getInstance().playSound(SoundManager.FON1_SOUND,1);
			}
			else{
				SoundManager.getInstance().stopSound(SoundManager.FON1_SOUND);
			}
			
		}
		
	}
}